﻿// Log4NetCtrl
// Log4Net Appender / User control for Windows Forms
// Copyright (C) 2009 Ralph Greschner
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Version history:
// ====================
//
// 04/10/2009: initial release
//   - still considered BETA
//

using System;

namespace Log4NetCtrl
{

	public partial class Log4NetCtrl
	{
		/// <summary>
		/// Inner redirector class.
		/// This class implements IAppender and
		/// redirects all input to the user control
		/// </summary>
		private class AppenderRedirector : log4net.Appender.IAppender {
			
			#region Class members
			/// <summary>Name of this Appender.</summary>
			string name = "Log4NetCtrl";
			
			/// <summary>
			/// User control which instanciated this
			/// redirector.
			/// Target of redirections.
			/// </summary>
			Log4NetCtrl ctrl;
			
			#endregion
			
			#region Getters / Setters
			
			/// <summary>
			/// Property for Name.
			/// </summary>
			public string Name {
				get {
					return name;
				}
				set {
					name = value;
				}

			}
			#endregion
			
			#region Implemented methods of IAppender
			
			/// <summary>
			/// Close the Appender.
			/// </summary>
			public void Close(){}
			
			/// <summary>
			/// Append the LoggingEvent.
			/// </summary>
			/// <param name="loggingEvent">Event to log.</param>
			public void DoAppend(log4net.Core.LoggingEvent loggingEvent){
				ctrl.AppenderDoAppend(loggingEvent);
			}
			
			#endregion
			
			#region Constructors
			
			/// <summary>
			/// Default ctor.
			/// </summary>
			/// <param name="p_ctrl">Instanciating Log4NetCtrl.</param>
			public AppenderRedirector(Log4NetCtrl p_ctrl){
				ctrl = p_ctrl;
			}
			
			#endregion
		}
	}
}
